package com.gogowan.agroenterprise;

import java.io.File;
import java.io.InvalidClassException;

import com.android.volley.manager.RequestManager;
import com.gogowan.agroenterprise.contorl.AppExcepiton;
import com.gogowan.agroenterprise.contorl.HttpConnectService;
import com.gogowan.agroenterprise.utils.PalUtils;
import com.lidroid.xutils.exception.HttpException;

import android.annotation.TargetApi;
import android.app.Activity;
import android.app.Application;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.StrictMode;
import android.widget.ProgressBar;
import android.widget.TextView;

public class MyApplication extends Application {

	public static final String MY_USER_INFO = "saveLoginInfo";
	public static final String NEW_OUT_STORAGE = "new_out_storage";
	public static final String NEW_OUT_STORAGE_RETURN = "new_out_storage_return";
	public static final String NEW_EDIT_ORDER = "new_edit_order";
	private static MyApplication instance;
	private AppExcepiton  app = AppExcepiton.getInstance();
	public static SharedPreferences.Editor editor=null;
	public static SharedPreferences mSettings = null;
	public static  String PREFS_NAME = "LoginINfo"; // 偏好设置名称
	public static  String CHUKU_JINGXIAOSHANG = "CHUKU_JINGXIAOSHANG"; // 出库经销商
	public static  String CHUKU_GONGCHANG = "CHUKU_GONGCHANG"; // 出库工厂
	public static  String TUIHUO_SAOMA_JINGXIAOSHANG = "TUIHUO_SAOMA_GONGCHANG"; //经销商扫码退货
	public static  String TUIHUO_SHOUDONG_JINGXIAOSHANG = "TUIHUO_SAOMA_GONGCHANG"; //经销商手动退货
	public static  String TUIHUO_SAOMA_GONGCHANG = "TUIHUO_SAOMA_GONGCHANG"; //工厂扫码退货
	public static  String TUIHUO_SHOUDONG_GONGCHANG = "TUIHUO_SHOUDONG_GONGCHANG"; //工厂手动退货
	public static  String ALL_LOGS = "allLogs"; //全部消息
	/**
	 * 单例，返回一个实例
	 *
	 * @return
	 */
	public static MyApplication getInstance() {
		return instance;
	}


	@Override
	public void onCreate() {
		super.onCreate();
		instance = this;
		if(!PalUtils.DEBUG){// 待改  开发过程中暂时把原来的异常捕获屏蔽了 20170103
			app.init(getApplicationContext());
		}
		mSettings = getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
		editor = mSettings.edit();
		RequestManager.getInstance().init(this);
	}

	@Override
	public void onLowMemory() {
		super.onLowMemory();
	}

	public void Download(Activity activity, TextView upText, ProgressBar bar, String url, final HttpConnectService.UrlErrorLestener urlErrorLestener){
		HttpConnectService hcs = new HttpConnectService(upText, bar);
		hcs.setOnErrorLestener(new HttpConnectService.UrlErrorLestener() {
			@Override
			public void ErrorMessage(HttpException errorException, String msg) {
				urlErrorLestener.ErrorMessage(errorException,msg);
			}
		});
		hcs.connectDownLoad(activity, activity.getPackageName(), url);
	}
}
